package dnl.jexem.remote.ssh;

import org.apache.commons.lang.StringUtils;

/**
 * Encapsulates the result of a single ssh command.
 * 
 * @author daniel
 * 
 */
public class SshCommandResult {
	private Integer exitCode;

	private String sysout;

	private String syserr;

	private String command;

	/**
	 * The exit code of the ensued command.
	 * 
	 * @return an <code>Integer</code> that matched the exit code or null if
	 *         no exit code can be retrieved.
	 */
	public Integer getExitCode() {
		return exitCode;
	}

	public void setExitCode(Integer exitCode) {
		this.exitCode = exitCode;
	}

	/**
	 * Gets the standard error of the command's process.
	 * 
	 * @return
	 */
	public String getSyserr() {
		return syserr;
	}

	public void setSyserr(String syserr) {
		this.syserr = syserr;
	}

	/**
	 * Gets the standard output of the command's process.
	 * 
	 * @return
	 */
	public String getSysout() {
		return sysout;
	}

	public void setSysout(String sysout) {
		this.sysout = sysout;
	}

	/**
	 * Gets the command.
	 * 
	 * @return
	 */
	public String getCommand() {
		return this.command;
	}

	public void setCommand(String command) {
		this.command = command;
	}

	public boolean hasErrors() {
		return this.syserr != null && !"".equals(syserr);
	}

	public String getDescription() {
		String sout = StringUtils.replace(sysout, "\n", "    \n");
		String serr = StringUtils.replace(syserr, "\n", "    \n");
		return "command  :\n    " + command + "\n" + "Sys out  :\n" + sout + "\n" + "Sys err  :\n"
				+ serr + "\n" + "Exit code: " + exitCode;
	}

	public String toString() {
		return this.getClass().getSimpleName() + "{\n" + getDescription() + "}";
	}

}
